/*
 * @Author: Haochen
 * @Date: 2021-11-20 17:32:48
 * @LastEditTime: 2021-11-25 18:54:49
 * @FilePath: \front\src\js\register.js
 */

import '../scss/common.scss';
import '../scss/register.scss';
import $ from './jquery-3.6.0.min.js';
import { getPromise } from './common.js';

$('#btn-to-login').click(function () {
  location.href = './login.html';
});

$('#btn-register').click(async function () {
  const obj = {
    username: $('#username').val(),
    userphone: $('#telephone').val(),
    userpass: $('#password').val(),
  };

  const { message, code } = await getPromise('/students/register', 'post', obj);

  $('#username').val('');
  $('#telephone').val('');
  $('#password').val('');

  if (code === 200) {
    alert(message);
    location.href = './login.html';
  } else {
    alert(message);
  }
});
